﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections.Specialized;

namespace TwitterPlugin
{
    public partial class frmConfig : Form
    {
        public bool Enabled;
        public string Token = string.Empty;
        public string TokenSecret = string.Empty;
        public string PIN = string.Empty;
        public decimal Interval;

        private oAuthTwitter _oAuth = new oAuthTwitter();

        public frmConfig(NameValueCollection current)
        {
            InitializeComponent();
            try
            {
                chkEnabled.Checked = bool.Parse(current["twitterplugin_enabled"]);
                nudInterval.Value = decimal.Parse(current["twitterplugin_interval"]);
            }
            catch
            {
                // ignore
            }
        }

        private void btnGetPin_Click(object sender, EventArgs e)
        {
            _oAuth.ConsumerKey = "XBdauVGJITAZerhSFsafvg";
            _oAuth.ConsumerSecret = "YaMfWB7gSgLfwFZDSQ3AZNDA5RLwMfPnmPJud7kbCzo";

            string authLink = _oAuth.AuthorizationLinkGet();
            System.Diagnostics.Process.Start(authLink);
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (string.Empty != txtPIN.Text)
            {
                try
                {
                    _oAuth.AccessTokenGet(_oAuth.OAuthToken, txtPIN.Text.Trim());
                    Token = _oAuth.Token;
                    TokenSecret = _oAuth.TokenSecret;
                    PIN = txtPIN.Text;
                }
                finally { }
            }
            Enabled = chkEnabled.Checked;
            Interval = nudInterval.Value;
        }
    }
}
